import 'package:flutter/material.dart';
import 'package:get/get.dart';
/*
使用方式
CustomPaint(
              size: const Size(PANEL_WIDTH_VALUE, PANEL_HEIGHT_VALUE),
              painter: MyCustomPainter(
                  frame:  'close'), //桢名字
            )
 */
class MyCustomPainter extends CustomPainter {
  final String frame;
  MyCustomPainter({super.repaint, required this.frame});
  @override
  void paint(Canvas canvas, Size size) {
    final Paint paint = Paint();
    var l = JSON_VALUE;
    if (l is List) {
      List<OutputFrame> data = l.map((e) => OutputFrame.fromJson(e)).toList();
      _drawBackgroundColor(canvas, size, Color(BACKGROUND_VALUE), paint);
      OutputFrame? outputData = data.firstWhereOrNull((p0) => p0.animationsName == frame);
      if (outputData != null) {
        _drawWidget(outputData.list, paint, canvas, size);
      }
    }
  }
  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
  void _drawBackgroundColor(
      Canvas canvas, Size size, Color backgroundColor, Paint paint) {
    canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height),
        paint..color = backgroundColor);
  }

  void _drawWidget(
      List<OutputBean> data, Paint paint, Canvas canvas, Size size) {
    for (var fakeWidget in data) {
      switch (fakeWidget.type) {
        SWITCH_VALUE
      }
    }
  }
  DRAW_EVENT_VALUE
}

class OutputBean {
  final int color;
  final double startY;
  final double endY;
  final double startX;
  final double endX;
  final double strokeWidth;
  final double rectLeft;
  final double rectTop;
  final double rectRight;
  final double rectBottom;
  final double angle;
  final double circleRadius;

  final List<OutputPoint> curvePointList;

  final String uuid;
  final String type;
  final String name;
  final String strokeCap;
  final String style;

  OutputBean(
      {required this.color,
      required this.startY,
      required this.endY,
      required this.startX,
      required this.endX,
      required this.strokeWidth,
      required this.rectLeft,
      required this.rectTop,
      required this.circleRadius,
      required this.rectRight,
      required this.rectBottom,
      required this.angle,
      required this.curvePointList,
      required this.uuid,
      required this.type,
      required this.name,
      required this.strokeCap,
      required this.style});

  static OutputBean fromJson(e) {
    List<OutputPoint> list = [];
    var l = e['curvePointList'];
    if (l is List) {
      list.addAll(l.map((e) => OutputPoint.fromJson(e)).toList());
    }
    return OutputBean(
        color: e['color'],
        startY: e['startY'],
        endY: e['endY'],
        startX: e['startX'],
        endX: e['endX'],
        strokeWidth: e['strokeWidth'],
        rectLeft: e['rectLeft'],
        rectTop: e['rectTop'],
        circleRadius: e['circleRadius'],
        rectRight: e['rectRight'],
        rectBottom: e['rectBottom'],
        angle: e['angle'],
        curvePointList: list,
        uuid: e['uuid'],
        type: e['type'],
        name: e['name'],
        strokeCap: e['strokeCap'],
        style: e['style']);
  }
}

class OutputPoint {
  final double startX;
  final double startY;
  final double endY;
  final double endX;

  OutputPoint(
      {required this.startX,
      required this.startY,
      required this.endY,
      required this.endX});

  static OutputPoint fromJson(e) {
    return OutputPoint(
        startX: e['startX'],
        startY: e['startY'],
        endY: e['endY'],
        endX: e['endX']);
  }
}

class OutputFrame {
  final String animationsName;
  final List<OutputBean> list;

  OutputFrame({required this.animationsName, required this.list});

  static OutputFrame fromJson(e) {
    List<OutputBean> list = [];
    var l = e['list'];
    if (l is List) {
      list.addAll(l.map((e) => OutputBean.fromJson(e)).toList());
    }
    return OutputFrame(animationsName: e['animationsName'], list: list);
  }
}
